
#ifdef __APPLE__
    #include <SDL/SDL.h>
    #include "SDL/SDL_opengl.h"
    #include "SDL/SDL_image.h"
#else
    #include <SDL/SDL.h>
    #include "GL/gl.h"
    #include "GL/glu.h"
#include <GL/glext.h>
    #include "SDL/SDL_image.h"
#endif

#include "BM_model.h"

BMModel::BMModel()
{
}

void BMModel::initModel(int type, float in_x, float in_y, float in_z)
{
    mod_type = type;

    switch (mod_type)
    {
        case MOD_OBJ:
           obj_object = new BMOBJ;
           moveModel(in_x, in_y, in_z);

           // we are going to use our obj_object object so we can delete the md2_object object
           md2_object = new BMMD2;
           delete md2_object;
        break;
        case MOD_MD2:
           md2_object = new BMMD2;
           moveModel(in_x, in_y, in_z);

           //md2_object->initMD2();

           // we are going to use our md2_object object so we can delete the obj_object object
           obj_object = new BMOBJ;
           delete obj_object;
        break;
    }
}

int BMModel::loadModel(char *path)
{
    int ret = 0;
    switch (mod_type)
    {
        case MOD_OBJ:
            ret = obj_object->loadOBJ(path);
        break;
        case MOD_MD2:
            ret = md2_object->loadMD2(path);
        break;
    }

    obj_object->printfObject(0,0,0,0,0,0,1);

    return ret;
}

/*
 * @param int Frames - the number of frames - MD2 Model
 * @param int CurFrame - The current frame - MD2 Model
*/
void BMModel::drawModel(int Frames)
{
    switch (mod_type)
    {
        break;
        case MOD_OBJ:
           obj_object->drawOBJ();
        break;
        case MOD_MD2:
           md2_object->drawMD2(Frames);
        break;
    }
}


void BMModel::freeModel()
{
    switch (mod_type)
    {
        case MOD_OBJ:
            obj_object->freeOBJ();
            delete obj_object;
        break;
        case MOD_MD2:
            md2_object->freeMD2();
            delete md2_object;
        break;
    }
}

void BMModel::moveModel(float in_x, float in_y, float in_z){

    switch (mod_type)
    {
        case MOD_OBJ:
            obj_object->moveOBJ(in_x, in_y, in_z);
        break;
        case MOD_MD2:
            md2_object->moveMD2(in_x, in_y, in_z);
        break;
    }
}

float BMModel::getX()
{
    switch (mod_type)
    {
        case MOD_OBJ:
            return obj_object->getX();
        break;
        case MOD_MD2:
            return md2_object->getX();
        break;
    }

    return 0.0f;
}

float BMModel::getY()
{
    switch (mod_type)
    {
        case MOD_OBJ:
            return obj_object->getY();
        break;
        case MOD_MD2:
            return md2_object->getY();
        break;
    }

    return 0.0f;
}

float BMModel::getZ()
{
    switch (mod_type)
    {
        case MOD_OBJ:
            return obj_object->getZ();
        break;
        case MOD_MD2:
            return md2_object->getZ();
        break;
    }

    return 0.0f;
}
